package com.exam.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.mapper.TeacherMapper;
import com.exam.pojo.Login;
import com.exam.pojo.Teacher;
import com.exam.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;
    @Override
    public Teacher getTeacher(Login login) {
        Teacher teacher = new Teacher();
        byte[] psd = login.getPassword().getBytes();
        String psdMd = DigestUtils.md5DigestAsHex(psd);
        teacher.setTeacherId(login.getUsername()).setPwd(psdMd);
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>(teacher);
        Teacher teacher1 = teacherMapper.selectOne(queryWrapper);
        return teacher1;
    }

    @Override
    public IPage<Teacher> findTeacherAll(Page<Teacher> teacherPage) {

        return teacherMapper.findTeacherAll(teacherPage);
    }





    @Override
    public Object findTeacherById(Integer teacherId) {
        return teacherMapper.findTeacherById(teacherId);
    }

    @Override
    public Object deleteTeacherById(Integer teacherId) {
        return teacherMapper.deleteTeacherById(teacherId);
    }

    @Override
    public Object updateTeacher(Teacher teacher) {
        return teacherMapper.updateTeacher(teacher);
    }
    @Override
    public Object add(Teacher teacher) {
        return teacherMapper.add(teacher);
    }
}
